﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Article_GWArt : System.Web.UI.Page
{
    public int ArtID
    {
        get { return Convert.ToInt32(ViewState["_ArtID"]); }
        set { ViewState["_ArtID"] = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ArtID = DongDong.Common.Misc.GetQueryStringAsInt("ArtID");
            if (ArtID != 0)
            {
                GetArticleInfo();
            }
        }
    }
    public void GetArticleInfo()
    {
        Article objInfo = Article.Get(ArtID);
        if (objInfo != null)
        {
            txtBiaoTi.Text = objInfo.Title;
            //txtNeiRong.Text = objInfo.link;
        }
    }
    protected void btn_search_Click_Click(object sender, EventArgs e)
    {
        Article objArticle = new Article();
        if (ArtID != 0)
        {
            objArticle = Article.Get(ArtID);
        }
        objArticle.Title = txtBiaoTi.Text.Trim();
        //objArticle.link = txtNeiRong.Text.Trim();
        if (ArtID != 0)
        {
            objArticle.Update();
            Page.ClientScript.RegisterStartupScript(this.GetType(), "success2", "<script>alert('修改')</script>");
        }
        else
        {
            objArticle.Type = (int)Article.type.购物;
            objArticle.Add();
            Page.ClientScript.RegisterStartupScript(this.GetType(), "success1", "<script>alert('添加成功')</script>");
        }
        PopulateArticleList();
    }

    public void PopulateArticleList()
    {
        Lv_ArtList.DataSource = Article.GetAllByType((int)(int)Article.type.购物);
        Lv_ArtList.DataBind();
    }

    protected void Lv_ArtList_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        Article.Delete(DongDong.Common.Misc.ConvertToInt(Lv_ArtList.DataKeys[e.ItemIndex].Value));
        PopulateArticleList();
    }
    protected void Lv_ArtList_PagePropertiesChanged(object sender, EventArgs e)
    {
        PopulateArticleList();
    }
    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (Lv_ArtList.Items.Count == 0)
            PopulateArticleList();
    }
}